package com.ymatou.shoppingcart.api.service;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.ymt.base.YmatouBaseCall;
import com.ymt.core.tool.FormatUtil;
import com.ymttest.common.entitie.ShoppingCartItems1;
import com.ymttest.common.entitie.Total;
import com.ymttest.utils.EnvSetup;

/**
 * 获取购物车拆单后信息Call FreeMaker Template自动生成代码
 */
public class GetShoppingCartItemsForOrderCall extends YmatouBaseCall {
	private static String opurl = "api/query/GetShoppingCartItemsForOrder";

	public GetShoppingCartItemsForOrderCall() {
		super(EnvSetup.getSystemUrl("api_shoppingcart"), opurl, "GET", "PARAM");
	}

	/**
	 * 获取Code
	 * 
	 * @return Code
	 */
	public String getCode() {
		String Code = null;
		try {
			JSONObject jo = new JSONObject(getReturnData());
			Code = String.valueOf(jo.get("Code"));

		} catch (Exception e) {
			e.printStackTrace();
		}
		return Code;
	}

	/**
	 * 获取BCode
	 * 
	 * @return BCode
	 */
	public String getBCode() {
		String BCode = null;
		try {
			JSONObject jo = new JSONObject(getReturnData());
			BCode = String.valueOf(jo.get("BCode"));

		} catch (Exception e) {
			e.printStackTrace();
		}
		return BCode;
	}

	/**
	 * 获取Msg
	 * 
	 * @return Msg
	 */
	public String getMsg() {
		String Msg = null;
		try {
			JSONObject jo = new JSONObject(getReturnData());
			Msg = (String) jo.get("Msg");

		} catch (Exception e) {
			e.printStackTrace();
		}
		return Msg;
	}

	/**
	 * 获取Data
	 * 
	 * @return Data
	 */
	public JSONObject getData() {
		JSONObject Data = null;
		try {
			JSONObject jo = new JSONObject(getReturnData());
			Data = jo.getJSONObject("Data");

		} catch (Exception e) {
			e.printStackTrace();
		}
		return Data;
	}

	/**
	 * 获取第一层 ShoppingCartItems
	 * 
	 * @return JSONArray
	 */
	public List<ShoppingCartItems1> getShoppingCartItems() {
		List<ShoppingCartItems1> sclist = new ArrayList<ShoppingCartItems1>();
		try {
			JSONArray list = getData().getJSONArray("ShoppingCartItems");
			for (int i = 0; i < list.length(); i++) {
				ShoppingCartItems1 sc1 = (ShoppingCartItems1) FormatUtil.GSONToObject(list.getString(i),
						ShoppingCartItems1.class);
				sclist.add(sc1);
			}
		} catch (JSONException e1) {
			e1.printStackTrace();
		}

		return sclist;
	}

	/**
	 * 获取第一层 Total
	 * 
	 * @return JSONObject
	 */
	public Total getTotal() {
		Total total = null;
		try {
			total = (Total) FormatUtil.GSONToObject(getData().getString("Total"), Total.class);

		} catch (Exception e) {
			e.printStackTrace();
		}
		return total;
	}
}